package demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

public class InputStream01 {
    public static void main(String[] args) {
        String filepath = "E:" + File.separator + "class2110" + File.separator + "text.txt";

        File file = new File(filepath); // 创建文件对象

        try {
            // 创建输出流对象
            InputStream inputStream = new FileInputStream(file);

            byte[] content = new byte[1024]; // 用于存放读取到的字节数据
            int length = inputStream.read(content);

            System.out.println(new String(content, 0, length));

            // 关闭输出流，否则会占用资源
            inputStream.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
